package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.mapper.DishMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关联接口")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result<PageResult> pagination(DishPageQueryDTO pageQueryDTO){
        PageResult dishPage = dishService.pagination(pageQueryDTO);
        return Result.success(dishPage);
    }

    /**
     *批量删除菜品
     */
    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result<String> deleteById(Long[] ids){
        dishService.deleteById(ids);
        return Result.success();
    }

    /**
     * 添加菜品
     */
    @PostMapping
    @ApiOperation(value = "添加菜品")
    public Result<String> addDish(@RequestBody DishDTO dishDTO){
        dishService.addDishWithFlavor(dishDTO);
        return Result.success();
    }

    /**
     * 停售或起售菜品
     */
    @PostMapping("/status/{status}")
    @ApiOperation(value = "起售或停售菜品")
    public Result<String> startOrStop(@PathVariable int status,long id){
        dishService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 修改菜品
     */
    @PutMapping()
    @ApiOperation(value = "修改菜品")
    public Result<String> updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }
    /**
     * 根据id查询菜品
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询菜品")
    public Result<DishVO> getDishById(@PathVariable Long id){
        DishVO dishVO = dishService.getDishById(id);
        return Result.success(dishVO);
    }
    /**
     * 根据分类id查询菜品
     */
    @GetMapping("/list")
    @ApiOperation(value = "根据分类id查询菜品")
    public Result<List<DishVO>> getDishes(Integer categoryId){
        List<DishVO> dishes = dishService.getDishByCategoryId(categoryId);
        return Result.success(dishes);
    }
}
